#  cmod - set up the user environment with module files.
#  Copyright (C) 1997, 1998 by the authors of cmod (see AUTHORS).
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */

## Process this file with automake to produce Makefile.in

SUBDIRS = testsuite
AUTOMAKE_OPTIONS = ansi2knr gnu
RM = rm -f

info_TEXINFOS = cmod.texi

# How to build the cmod binary.
libexec_PROGRAMS = cmod
cmod_SOURCES = cmod.c cmod_alloc.c cmod_parse.c cmod_trace.c env.c \
	cmod_alloc.h cmod_main.h cmod_parse.h cmod_trace.h env.h unused.h \
	cmod_dirent.h archaic.h cmod_string.c cmod_string.h \
	cmod_token.h cmod_token.c cmod_preproc.h cmod_pp.c \
	cmod_process.h cmod_proc.c cmod_wait.h cmod_strp.h \
	cmod_strn.h
cmod_LDADD = @LIBOBJS@
CMOD=$(libexecdir)/cmod

BUILT_SOURCES = cmod_strn.h

EXTRA_DIST = .cvsignore create_sample README.DEVO RELEASING MACHINES \
	bash.in tcsh.in zsh.in ksh.in \
	sh.in path.sh.in \
	csh.in path.csh.in

pkgsysconfdir=$(sysconfdir)/@PACKAGE@

# We don't install any module files, except with the special
# install-sample target.
moduledir=$(pkgsysconfdir)/modulefiles
module_DATA = 
install-sample:
	$(srcdir)/create_sample $(moduledir)

# Init files, to be sourced from the shell startup files.
pkgsysconf_SCRIPTS = path.sh path.csh \
	sh.init csh.init bash.init tcsh.init zsh.init ksh.init
SUFFIXES = .in .init
.in.init:
	$(RM) $@ $@.tmp
	sed -e 's%@CMOD@%$(CMOD)%g' \
	    -e 's%@MODULEPATH@%$(moduledir)%g' \
	    -e 's%@INIT@%$(pkgsysconfdir)%g' \
	    < $< > $@.tmp
	chmod +x $@.tmp
	mv $@.tmp $@

path.sh: path.sh.in
	$(RM) $@ $@.tmp
	sed -e 's%@INIT@%$(pkgsysconfdir)%g'< $(srcdir)/path.sh.in > $@.tmp
	chmod +x $@.tmp
	mv $@.tmp $@

path.csh: path.csh.in
	$(RM) $@ $@.tmp
	sed -e 's%@INIT@%$(pkgsysconfdir)%g'< $(srcdir)/path.csh.in > $@.tmp
	chmod +x $@.tmp
	mv $@.tmp $@

# Clean target support.
MOSTLYCLEANFILES = *.init *.tmp path.sh path.csh enforce-recheck

# Remove all files that automake installs.  Note: keep this list
# in sync with the list of files to remove mentioned in the file
# RELEASING so that these are regenereated during a release build!
MAINTAINERCLEANFILES = COPYING INSTALL Makefile.in aclocal.m4 \
	ansi2knr.1 ansi2knr.c config.h.in configure install-sh \
	mdate-sh missing mkinstalldirs texinfo.tex

noinst_DATA = enforce-recheck
enforce-recheck: cmod
	$(RM) testsuite/*.outss testsuite/*.outsg testsuite/*.outgs \
	    testsuite/*.outgg
	echo timestamp > enforce-recheck

cmod_strn.h: cmod_strp.h
	$(RM) $@ $@.tmp
	echo '/* Generated by Makefile from cmod_strp.h.  Do not edit. */' \
		> $@.tmp
	sed 's/\(extern.*\)(.*)/\1()/' < $(srcdir)/cmod_strp.h >> $@.tmp
	echo '/* Generated by Makefile from cmod_strp.h.  Do not edit. */' \
		>> $@.tmp
	mv $@.tmp $@

# The dependencies that are automatically generated when the
# distribution is made does not include cmod_strn.h (since the
# distribution is made with gcc that understands prototypes).
# This dependency is here so that the dependencies are correct on
# computers without prototypes.
cmod_string.h: cmod_strn.h

# Recheck everything.
recheck:
	$(RM) testsuite/*.outss testsuite/*.outsg testsuite/*.outgs \
	    testsuite/*.outgg
	$(MAKE) check

# Check that no non-portable file names are included in the
# distribution.  This test was borrowed from the makefile of 
# automake 1.3b.
path-check: distdir
	(cd $(distdir) && \
	  find . -print | xargs pathchk -p); \
	  status=$$?; \
	  rm -rf $(distdir); \
	  exit $$status

index-check:
	egrep '^@..?index ' $(srcdir)/cmod.texi \
	| sort | uniq -c | sort -nr

# This target is used by the automatic distributed test driver to
# gather information about the used setup.  It is probably not useful
# for anyone except the cmod maintainers.
identify:
	@echo Uname: `uname -a`
	@echo CC: $(CC)
	@echo CFLAGS: $(CFLAGS)
	@echo Compiler version: `$(CC) -v 2>&1`
